from django.db import models
from django.contrib.syndication.feeds import Feed

# Create your models here.
class Comment(models.Model):
    post = models.ForeignKey('Post')
    author = models.CharField(max_length=255)
    date = models.DateTimeField()
    content = models.TextField()

class Post(models.Model):
    title = models.CharField(max_length=255)
    author = models.CharField(max_length=255)
    date = models.DateTimeField()
    content = models.TextField()
    
    def get_absolute_url(self):
        return '/codingdojo/blog/'

class RecentEntries(Feed):
    title = "tangerina coding dojo blog"
    link = "/codingdojo/blog/"
    description = "Updates on changes and additions to tangerina coding dojo blog."

    def items(self):
        return Post.objects.order_by('-date')[:20]
    
    def __init__(self, slug=None, request=None):
        if slug and request:
            super(RecentEntries, self).__init__(slug, request)
